define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chat/message/index' + location.search,
                    add_url: 'chat/message/add',
                    edit_url: 'chat/message/edit',
                    del_url: 'chat/message/del',
                    multi_url: 'chat/message/multi',
                    import_url: 'chat/message/import',
                    table: 'message',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'msg_id',
                sortName: 'msg_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'msg_id', title: __('Msg_id')},
                        // {field: 'id', title: __('Id'), operate: 'LIKE'},
                        // {field: 'from_user', title: __('From_user')},
                        {field: 'from_user_txt', title: __('From_user')},
                        // {field: 'to_user', title: __('To_user')},
                        {field: 'to_user_txt', title: __('To_user')},
                        // {field: 'chat_identify', title: __('Chat_identify'), operate: 'LIKE'},
                        {
                            field: 'type', title: __('Type'), operate: 'LIKE',
                            searchList: {
                                "text": __('Type_text'),
                                "file": __('Type_file'),
                                "image": __('Type_image'),
                                "video": __('Type_video'),
                                "event": __('Type_event'),
                            },
                            formatter: Table.api.formatter.normal
                        },

                        {
                            field: 'content', title: __('内容'), operate: 'LIKE',
                            align: 'left',
                            formatter:function(value,row, index){
                                if (!row) {
                                    return '-';
                                } else {
                                    if(row.type=='text'){
                                        return   '<div>' + "<span style='font-size: 14px;'> "  + row.content + " </span> <br/>" + '<div>' ;
                                    }else{
                                        return '-';
                                    }
                                }
                            },
                            cellStyle:{
                                css:{
                                    "white-space":"nowrap",     //单行省略必备
                                    "text-overflow":"ellipsis", //单行省略必备
                                    "overflow":"hidden",        //单行省略必备
                                    // "color":"#4E73DF",
                                    "max-width":"200px",
                                }
                            }},

                        {
                            field: 'image',
                            title: __('Type_image'),
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.images
                        },

                        {
                            field: 'music',
                            title: __('Music'),
                            events: Table.api.events.audio,
                            formatter: Controller.api.formatter.audio
                        },

                        {
                            field: 'video',
                            title: __('Type_video'),
                            events: Table.api.events.image,
                            operate: false,
                            formatter: function (row) {
                                if (!row) {
                                    return '-';
                                } else {
                                    var str = row.split(",");
                                    var html = '';
                                    for (var i = str.length - 1; i >= 0; i--) {
                                        html += "<a href='" + str[i] + "'target='_blank' class='fa fa-video-camera'>&nbsp;";
                                    }
                                    html += '';
                                    return html;
                                }
                            }
                        },

                        {
                            field: 'is_read', title: __('Is_read'),
                            searchList: {
                                "1":__('Is_read1'),
                                "0":__('Is_read0'),
                            },

                            formatter: Table.api.formatter.normal
                        },
                        // {field: 'is_last', title: __('Is_last'),
                        //     searchList: {
                        //         "1":__('是'),
                        //         "0":__('否'),
                        //     },
                        //     formatter: Table.api.formatter.normal
                        // },
                        {
                            field: 'create_time',
                            title: __('Create_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        // {
                        //     field: 'is_undo', title: __('Is_undo'),
                        //     searchList: {
                        //         "1":__('是'),
                        //         "0":__('否'),
                        //     },
                        //     formatter: Table.api.formatter.normal
                        // },
                        // {field: 'pid', title: __('Pid'),operate:false},
                        // {field: 'file_id', title: __('File_id'),operate:false},
                        // {field: 'file_cate', title: __('File_cate')},

                        // {field: 'file_size', title: __('File_size'),operate:false },
                        // {
                        //     field: 'file_name', title: __('File_name'), operate: 'LIKE',
                        //     formatter:Table.api.formatter.files,
                        // },

                        // {
                        //     field: 'extends', title: __('Extends'),
                        //     formatter: Table.api.formatter.content,
                        //     width:100, class:'autocontent', hover: true,
                        //     operate:false
                        // },

                        // {
                        //     field: 'status', title: __('Status'),
                        //     searchList: {
                        //         "1":__('Status1'),
                        //         "0":__('Status0'),
                        //     },
                        //     formatter: Table.api.formatter.normal,
                        //     operate:false
                        // },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                audio: function (value, row, index) {
                    if (value != null) {
                        return '<a href="#" onClick="playAudio(\'' + value + '\'); return false;"><i class="fa fa-volume-up"></i></a>';
                    }

                },
            },
        }
    };
    return Controller;
});
